//
//  FQDDotLoadingView.m
//  FakeQDaily
//
//  Created by mewxiv on 9/11/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDDotLoadingView.h"

static NSInteger const FQDLoadingImageNum = 21;
static NSString *const FQDLoadingImageNameFormat = @"list_loading_%03ld";

@interface FQDDotLoadingView ()

@property (nonatomic, strong) NSArray *animImages;

@end

@implementation FQDDotLoadingView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self commonInit];
        [self loadImages];
    }
    return self;
}

- (void)commonInit
{
    self.opaque = YES;
//    self.backgroundColor = [UIColor whiteColor];
//    self.clipsToBounds = YES;
}

- (void)loadImages
{
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:FQDLoadingImageNum];
    for (NSInteger i = 1; i <= FQDLoadingImageNum; i++) {
        NSString *imageName = [NSString stringWithFormat:FQDLoadingImageNameFormat, (long)i];
        UIImage *image = [UIImage imageNamed:imageName];
        [images addObject:image];
    }
    self.animationImages = images;
    self.animationDuration = 2.0f;
    self.animationRepeatCount = INFINITY;
    self.contentMode = UIViewContentModeCenter;
    self.layer.contentsScale = 2.0f;
}

- (void)startLoading
{
    [self startAnimating];
}

- (void)endLoading
{
    if ([self isAnimating]) {
        [self stopAnimating];
    }
}

@end
